package com.cry.webapp.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.struts2.ServletActionContext;

import com.cry.app.core.log.Logger;
import com.opensymphony.xwork2.Preparable;

public abstract class ActionSupport extends com.opensymphony.xwork2.ActionSupport implements Preparable {

	private String namespace = null;
    protected HttpServletRequest request = ServletActionContext.getRequest();
    protected HttpServletResponse response = ServletActionContext.getResponse(); 
    {
        response.setCharacterEncoding("UTF-8");
    }

	public String getNamespace() {

		if(namespace == null) {
			String servletPath = (String) request.getAttribute("struts.request_uri");
			
			/*
			 * Create namespace from request uri 
			 */
			if(servletPath != null) {
				int i=servletPath.length()-1;
				do {
					if(servletPath.charAt(i) == '/') break;
				} while(i-- >= 0);
				
				namespace=servletPath.substring(request.getContextPath().length(),i);
				
			}
		}
		return namespace;
	}
	

}
